﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using FH.Application.NewsApp;
using FH.Application.PorductApp.Dtos;
using FH.Application.UserApp;
using Microsoft.AspNetCore.Mvc;
using WebSite.Models;

namespace WebSite.Controllers
{
    public class HomeController : FHController
    {
        private readonly INewsAppService _service;
        private readonly IProductAppService _productService;
       
        public HomeController(INewsAppService service
            , IProductAppService productService
            , ISettingService settingService):base(settingService)
        {
            _service = service;
            _productService = productService;
          
        }

        public IActionResult Index()
        {
            int total = 0;
            List<CategoryDto> categories = _productService.GetCategoryDtos(1, 100, out total);
            List<ProductDto> products = null;
            ViewBag.Categorys = categories;
            if (categories != null && categories.Any())
            {
                products = _productService.GetProducts(categories[0].Id, 1, 3, out total);
            }
            ViewBag.Products = products;
            ViewBag.News= _service.GetNewsPage(1, 100, out total);
            ViewBag.Banners = _settingService.GetBannerPage(1, 100, out total);
            ViewBag.Customer = _settingService.GetCustomerPage(1, 100, out total);
            return View();
        }
        public IActionResult Data(Guid category)
        {
            int total = 0;
            List<ProductDto> products = _productService.GetProducts(category, 1, 100, out total);
            return Json(products);
        }
        public IActionResult About()
        {
            ViewBag.AppConfig = _settingService.GetAppConfig();
            return View();
        }

        public IActionResult Contact()
        {
           

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
